<?php

namespace app\common\traits\controller;

use think\Cache;
use think\Session;
use think\Config;
use think\Request;
use think\Exception;

trait TraitController
{
    public function _initialize()
    {
        if (!Config::get('lang_switch_on')) {
            throw new Exception("open lang_switch_on", 1);            
        }

        Session::init(['prefix' => '','auto_start' => true, 'domain' => Config::get('url_domain_root')]);

        $this->init();        
    }

    /**
     * 初始化操作
     * @return [type] [description]
     */
    protected function init(){}

    public function clearCache()
    {
        return Cache::clear(); 
    }
    
    public static function flash()
    {
        Session::flash('_old_input', Request::instance()->param());
    }

    public static function old($value = '')
    {
        if ($value) {
            return Session::get('_old_input.'.$value);
        }
        return Session::get('_old_input');
        
    }
}
